<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<form>
    账号：<input type="text" id="username" name="username"> <br/>
    密码：<input type="password" id="password" name="password"> <br/>
    <input type="button" value="登 录" onclick="login()">
</form>
</body>
<script type="text/javascript">
    function login() {
        let username = document.getElementById('username').value;
        let password = document.getElementById('password').value;
        let formData = new FormData();
        formData.append('username', username);
        formData.append('password', password);
        axios.post('http://localhost:8085/user/login', formData)
            .then( (response) => {
                //进行登录结果的判断，和 页面的跳转
                if (response.data.code === 200) {
                    //表示登录成功
                    window.localStorage.setItem("loginToken", response.data.data);
                    window.location.href = "welcome.html"
                } else {
                    alert("登录失败，原因：" + response.data.msg);
                }
            })
            .catch( (error) => {
                console.log(error);
            });
    }
</script>
</html>